# 导包
import requests
import config

# 创建接口类
class LoginAPI:
    # 出初始化
    def __init__(self):
        self.url_verify = config.BASE_URL + "/api/captchaImage"
        self.url_login = config.BASE_URL + "/api/login"

    # 获取验证码
    def get_verify_code(self):
        return requests.get(url=self.url_verify)

    # 登录
    def login(self,login_data):
        return requests.post(url=self.url_login, json=login_data)

if __name__ == '__main__':
    # 实例化接口对象
    login_api = LoginAPI()
    # 获取图片验证码
    res_v = login_api.get_verify_code()
    # 获取响应数据中的uuid值
    uuid = res_v.json().get("uuid")
    # 登录
    login_data = {
        "username":"admin",
        "password":"admin123",
        "code":"2",
        "uuid":uuid
    }
    res_l = login_api.login(login_data)
    print(res_l.status_code)
    print(res_l.json())
    print(res_l.json().get("token"))
